package br.com.ToComFome.classes;

import java.util.List;

import br.com.ToComFome.R;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ExpandableListAdapter extends BaseExpandableListAdapter {
	 
    private Activity context;
    private List<ItemListView> menus;
 
    public ExpandableListAdapter(Activity context, List<ItemListView> menus){
        this.context = context;
        this.menus = menus;
    }
 
    public Object getChild(int groupPosition, int childPosition) {
    	return menus.get(groupPosition).getSubItems().get(childPosition);
    }
 
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }
     
     
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        final SubItemListView subItemListView = (SubItemListView)getChild(groupPosition, childPosition);
         
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.list_view_style_sub_group, null);
        }
        TextView titulo = (TextView)convertView.findViewById(R.id.txtTitleSub);
        TextView subTitulo = (TextView)convertView.findViewById(R.id.txtSubTitleSub);
        ImageView img = (ImageView)convertView.findViewById(R.id.imgListViewSub);
        
        titulo.setText(subItemListView.getTxt_titulo());
        subTitulo.setText(subItemListView.getTxt_sub());
        img.setImageResource(subItemListView.getId_img());
        
        return convertView;
    }
 
    public int getChildrenCount(int groupPosition) {
        return menus.get(groupPosition).getSubItems().size();
    }
 
    public Object getGroup(int groupPosition) {
        return menus.get(groupPosition);
    }
 
    public int getGroupCount() {
        return menus.size();
    }
 
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }
 
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        final ItemListView itemListView = (ItemListView)getGroup(groupPosition);

        if (convertView == null) {
            convertView = View.inflate(context, R.layout.list_view_style, null);
        }
        TextView titulo = (TextView)convertView.findViewById(R.id.txtTitle);
        ImageView img = (ImageView)convertView.findViewById(R.id.imgListView);
        
        titulo.setText(itemListView.getTxt_titulo());
        img.setImageResource(itemListView.getId_img());
        
        return convertView;
    }
 
    public boolean hasStableIds() {
        return true;
    }
 
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}